/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.lang.reflect.Method;

/**
 * <p>Project: jse2303 - Reflect01</p>
 * <p>Powered by webrx On 2023-07-28 11:02:27</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reflect05 {
    public static void main(String[] args) throws Exception {
        //反射获取 方法
        Class<Apple> c = Apple.class;

        Ann ann1 = c.getAnnotation(Ann.class);
        System.out.println(ann1.age());
        System.out.println(ann1.name());

        //c.getDeclaredMethods()
        //Method m = c.getDeclaredMethod(...)
        //c.getMethods()
        //Method m = c.getMethod(...)

        //for (Method m : c.getDeclaredMethods()) {
        //    System.out.println(m.getName());
        //}


        Object o = c.getConstructor().newInstance();
        Method show = c.getMethod("show");
        show.invoke(o);

        Method pf = c.getMethod("pf", int.class);
        Object invoke = pf.invoke(o, 16);
        int nn = (int) invoke;
        System.out.println(nn);

        Ann ann = pf.getAnnotation(Ann.class);
        System.out.println(ann.name());

    }
}
